#define _GNU_SOURCE
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>


void *thread_func1(void *arg)
{   int i=0;
    while(1)
    {   i++;
        printf("thread1: %d *******\n",gettid());
        sleep(1);
        if(i==5)
        {
            return NULL;
           // pthread_exit(NULL);
        }
    }


}

void *thread_func2(void *arg)
{
    while(1)
    {
        printf("thread2: %d #########\n",gettid());
        sleep(1);
    }
}


int main(int argc, char const *argv[])
{
    pthread_t thread1,thread2;

    pthread_create(&thread1,NULL,thread_func1,NULL);
    pthread_create(&thread2,NULL,thread_func2,NULL);
    sleep(10);
    pthread_cancel(thread2);

    pthread_join(thread1,NULL);
    pthread_join(thread2,NULL);

    return 0;
}
